package com.sky.controller.admin;


import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.Put;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/admin/order")
@RestController("adminOrderController")
@Api(tags = "管理端订单相关接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {

        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 查询各个状态订单
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("查询各个状态订单")
    public Result<OrderStatisticsVO> orderStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.orderStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询详单
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询详单")
    public Result<OrderVO>  orderDetail(@PathVariable Long id){

        OrderVO orderVO = orderService.orderDetail(id);

        return Result.success(orderVO);
    }

    /**
     * 接单
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody Orders orders){

        orderService.confirm(orders);

        return Result.success();
    }

    /**
     * 拒单
     * @param orders
     * @return
     */
    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody Orders orders){

        orderService.rejection(orders);
        return Result.success();
    }

    /**
     * 取消
     * @param orders
     * @return
     */
    @PutMapping("cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody Orders orders){
        orderService.cancel(orders);
        return Result.success();
    }

    /**
     * 派单
     * @param id
     * @return
     */
    @PutMapping("delivery/{id}")
    @ApiOperation("取消订单")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    } /**
     * 派单
     * @param id
     * @return
     */
    @PutMapping("complete/{id}")
    @ApiOperation("取消订单")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }




}
